/**
 * ReportGear(2011)
 */
package com.reportgear.report.model.headerfooter.paintable;

import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;

import net.abbp.report.model.cell.style.FontStyle;
import net.abbp.report.model.headerfooter.HFElement;
import net.abbp.report.model.headerfooter.TextHFElement;

import com.reportgear.report.view.grid.util.GraphHelper;

/**
 * 页脚页面文本绘制器
 * 
 * @version 1.0 2011-4-23
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class TextHFPaintable extends AbstractHFPaintable {
	private TextHFElement element;

	public TextHFPaintable(TextHFElement element) {
		this.element = element;
	}

	public TextHFPaintable(Point2D point, TextHFElement element) {
		super(point);
		this.element = element;
	}

	public HFElement getHFElement() {
		return this.element;
	}

	public void paint(Graphics2D g2) {
		FontStyle fontStyle = this.element.getFontStyle();
		FontMetrics fm = g2.getFontMetrics(fontStyle);
		Font font = g2.getFont();
		g2.setPaint(fontStyle.getForeground());
		g2.setFont(fontStyle);
		
		String text = this.element.getText();

		String[] lines = text.split("\n");
		FontMetrics fontMetrics = GraphHelper.getFontMetrics(fontStyle);

		int h = 0;
		for (String line : lines) {
			GraphHelper.drawString(g2, line, getPaintLocation().getX(), h + getPaintLocation().getY() + fm.getAscent());
			h += fm.getHeight();
		}

		g2.setFont(font);
	}
}
